﻿// Inner Fire 游戏引擎库
// MapSetting 地图设置
//
// Copyright (c) 2025 by 尔西大帝. All rights reserved.
//
// 所属层级：应用层(4)
// 用于地图的配置，各种代码代表的意义
//
// Author: 尔西大帝
// Email: 2670613871@qq.com
// Created: 2025-06-14

#include "map_setting.h"

namespace ifire::game {
TerrainSetting::TerrainSetting() : name(), tex(0.0f, 0.0f), code(0) {}

TerrainSetting::TerrainSetting(const ikit::XmlNode& node)
    : name(node("Name")), tex(node("Tex")), code(0) {
  if (node("Code").value) {
    code = node("Code").value[0];
  }
}

MapSetting::MapSetting(ConfigManager* manager, const ikit::XmlNode& node)
    : ConfigInfo(manager, node("Name"))
    , terrain_model(node("TerrainModel"))
    , sea_level(node("SeaLevel")) {
  node.ReadItems("Terrain", terrains_);
}

MapSetting::~MapSetting() {}

const TerrainSetting& MapSetting::GetTerrain(int code) const {
  static TerrainSetting EMPTY = TerrainSetting();
  for (auto& e : terrains_) {
    if (e.code == code) {
      return e;
    }
  }
  return EMPTY;
}

} // namespace ifire::game